package chapter6;

import java.util.Scanner;

/****************************************************************
 * Author：icynlau
 * Description: 打印税表
 * Date:2021/4/4
 * ***************************************************************
 */
public class exc6_15 {
	
	public static void main(String[] args) {

		System.out.print("Taxable		Single		Married Joint	Married       Head of \n");
		System.out.print("Income				    	    	                Separate	    a House\n");
		System.out.print("=============================================\n");
		for(int i=0;i<200;i++) {
			System.out.printf("%d           %d             %d              %d         %d\n", 500000+50*i
					,Math.round(computeTax(0,500000+50*i)),Math.round(computeTax(1,500000+50*i)),Math.round(computeTax(2,500000+50*i)),Math.round(computeTax(3,500000+50*i)));
		}
		
	}
	
	public static double computeTax(int status,double taxableIncome) {
		double income=taxableIncome;
		
		double tax=0;
		if(status==0) {
			
			if(income<=8350) {
				tax=income*0.1;
			}else if(income<=33950) {
				tax=8350*0.1+(income-8350)*0.15;
			}else if(income<=82250) {
				tax=8350*0.1+(33950-8350)*0.15+(income-33950)*0.25;
			}else if(income<=171550) {
				tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(income-82250)*0.28;
			}else if(income<=372950) {
				tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(income-171550)*0.33;
			}else {
				tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(372950-171550)*0.33+(income-372950)*0.35;
			}
			
			
		}else if(status==1) {
			
			if(income<=16700) {
				tax=income*0.1;
			}else if(income<=67900) {
				tax=16700*0.1+(income-16700)*0.15;
			}else if(income<=137050) {
				tax=16700*0.1+(67900-16700)*0.15+(income-67900)*0.25;
			}else if(income<=208850) {
				tax=16700*0.1+(67900-16700)*0.15+(137050-67900)*0.25+(income-137050)*0.28;
			}else if(income<=372950) {
				tax=16700*0.1+(67900-16700)*0.15+(137050-67900)*0.25+(208850-137050)*0.28+(income-208850)*0.33;
			}else {
				tax=16700*0.1+(67900-16700)*0.15+(137050-67900)*0.25+(208850-137050)*0.28+(372950-208850)*0.33+(income-372950)*0.35;
			}
			
			
		}else if(status==2) {
			
			if(income<=8350) {
				tax=income*0.1;
			}else if(income<=33950) {
				tax=8350*0.1+(income-8350)*0.15;
			}else if(income<=68525) {
				tax=8350*0.1+(33950-8350)*0.15+(income-33950)*0.25;
			}else if(income<=104425) {
				tax=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(income-68525)*0.28;
			}else if(income<=186475) {
				tax=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(104425-68525)*0.28+(income-104425)*0.33;
			}else {
				tax=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(104425-68525)*0.28+(186475-104425)*0.33+(income-186475)*0.35;
			}
			
			
		}else if(status==3) {
			
			if(income<=11950) {
				tax=income*0.1;
			}else if(income<=45500) {
				tax=11950*0.1+(income-11950)*0.15;
			}else if(income<=117450) {
				tax=11950*0.1+(45500-11950)*0.15+(income-45500)*0.25;
			}else if(income<=190200) {
				tax=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(income-117450)*0.28;
			}else if(income<=372950) {
				tax=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(190200-117450)*0.28+(income-190200)*0.33;
			}else {
				tax=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(190200-117450)*0.28+(372950-190200)*0.33+(income-372950)*0.35;
			}
			

			
		}else {
			System.out.println("Error: invalid status");
			System.exit(1);
			
		}
		
		
		return tax;
		
	}

}

/*
* 我的运行结果和书上201页的不同，但是我认为时书错了
* 毕竟	taxable income为 400000的Single税费为 117683.5
* 运行结果如下：
Taxable		Single		Married Joint	Married       Head of 
Income				    	    	                Separate	    a House
=============================================
500000           152684             145362              160181         149360
500050           152701             145380              160199         149378
500100           152719             145397              160216         149395
500150           152736             145415              160234         149413
500200           152754             145432              160251         149430
500250           152771             145450              160269         149448
500300           152789             145467              160286         149465
500350           152806             145485              160304         149483
500400           152824             145502              160321         149500
500450           152841             145520              160339         149518
500500           152859             145537              160356         149535
500550           152876             145555              160374         149553
500600           152894             145572              160391         149570
500650           152911             145590              160409         149588
500700           152929             145607              160426         149605
500750           152946             145625              160444         149623
500800           152964             145642              160461         149640
500850           152981             145660              160479         149658
500900           152999             145677              160496         149675
500950           153016             145695              160514         149693
501000           153034             145712              160531         149710
501050           153051             145730              160549         149728
501100           153069             145747              160566         149745
501150           153086             145765              160584         149763
501200           153104             145782              160601         149780
501250           153121             145800              160619         149798
501300           153139             145817              160636         149815
501350           153156             145835              160654         149833
501400           153174             145852              160671         149850
501450           153191             145870              160689         149868
501500           153209             145887              160706         149885
501550           153226             145905              160724         149903
501600           153244             145922              160741         149920
501650           153261             145940              160759         149938
501700           153279             145957              160776         149955
501750           153296             145975              160794         149973
501800           153314             145992              160811         149990
501850           153331             146010              160829         150008
501900           153349             146027              160846         150025
501950           153366             146045              160864         150043
502000           153384             146062              160881         150060
502050           153401             146080              160899         150078
502100           153419             146097              160916         150095
502150           153436             146115              160934         150113
502200           153454             146132              160951         150130
502250           153471             146150              160969         150148
502300           153489             146167              160986         150165
502350           153506             146185              161004         150183
502400           153524             146202              161021         150200
502450           153541             146220              161039         150218
502500           153559             146237              161056         150235
502550           153576             146255              161074         150253
502600           153594             146272              161091         150270
502650           153611             146290              161109         150288
502700           153629             146307              161126         150305
502750           153646             146325              161144         150323
502800           153664             146342              161161         150340
502850           153681             146360              161179         150358
502900           153699             146377              161196         150375
502950           153716             146395              161214         150393
503000           153734             146412              161231         150410
503050           153751             146430              161249         150428
503100           153769             146447              161266         150445
503150           153786             146465              161284         150463
503200           153804             146482              161301         150480
503250           153821             146500              161319         150498
503300           153839             146517              161336         150515
503350           153856             146535              161354         150533
503400           153874             146552              161371         150550
503450           153891             146570              161389         150568
503500           153909             146587              161406         150585
503550           153926             146605              161424         150603
503600           153944             146622              161441         150620
503650           153961             146640              161459         150638
503700           153979             146657              161476         150655
503750           153996             146675              161494         150673
503800           154014             146692              161511         150690
503850           154031             146710              161529         150708
503900           154049             146727              161546         150725
503950           154066             146745              161564         150743
504000           154084             146762              161581         150760
504050           154101             146780              161599         150778
504100           154119             146797              161616         150795
504150           154136             146815              161634         150813
504200           154154             146832              161651         150830
504250           154171             146850              161669         150848
504300           154189             146867              161686         150865
504350           154206             146885              161704         150883
504400           154224             146902              161721         150900
504450           154241             146920              161739         150918
504500           154259             146937              161756         150935
504550           154276             146955              161774         150953
504600           154294             146972              161791         150970
504650           154311             146990              161809         150988
504700           154329             147007              161826         151005
504750           154346             147025              161844         151023
504800           154364             147042              161861         151040
504850           154381             147060              161879         151058
504900           154399             147077              161896         151075
504950           154416             147095              161914         151093
505000           154434             147112              161931         151110
505050           154451             147130              161949         151128
505100           154469             147147              161966         151145
505150           154486             147165              161984         151163
505200           154504             147182              162001         151180
505250           154521             147200              162019         151198
505300           154539             147217              162036         151215
505350           154556             147235              162054         151233
505400           154574             147252              162071         151250
505450           154591             147270              162089         151268
505500           154609             147287              162106         151285
505550           154626             147305              162124         151303
505600           154644             147322              162141         151320
505650           154661             147340              162159         151338
505700           154679             147357              162176         151355
505750           154696             147375              162194         151373
505800           154714             147392              162211         151390
505850           154731             147410              162229         151408
505900           154749             147427              162246         151425
505950           154766             147445              162264         151443
506000           154784             147462              162281         151460
506050           154801             147480              162299         151478
506100           154819             147497              162316         151495
506150           154836             147515              162334         151513
506200           154854             147532              162351         151530
506250           154871             147550              162369         151548
506300           154889             147567              162386         151565
506350           154906             147585              162404         151583
506400           154924             147602              162421         151600
506450           154941             147620              162439         151618
506500           154959             147637              162456         151635
506550           154976             147655              162474         151653
506600           154994             147672              162491         151670
506650           155011             147690              162509         151688
506700           155029             147707              162526         151705
506750           155046             147725              162544         151723
506800           155064             147742              162561         151740
506850           155081             147760              162579         151758
506900           155099             147777              162596         151775
506950           155116             147795              162614         151793
507000           155134             147812              162631         151810
507050           155151             147830              162649         151828
507100           155169             147847              162666         151845
507150           155186             147865              162684         151863
507200           155204             147882              162701         151880
507250           155221             147900              162719         151898
507300           155239             147917              162736         151915
507350           155256             147935              162754         151933
507400           155274             147952              162771         151950
507450           155291             147970              162789         151968
507500           155309             147987              162806         151985
507550           155326             148005              162824         152003
507600           155344             148022              162841         152020
507650           155361             148040              162859         152038
507700           155379             148057              162876         152055
507750           155396             148075              162894         152073
507800           155414             148092              162911         152090
507850           155431             148110              162929         152108
507900           155449             148127              162946         152125
507950           155466             148145              162964         152143
508000           155484             148162              162981         152160
508050           155501             148180              162999         152178
508100           155519             148197              163016         152195
508150           155536             148215              163034         152213
508200           155554             148232              163051         152230
508250           155571             148250              163069         152248
508300           155589             148267              163086         152265
508350           155606             148285              163104         152283
508400           155624             148302              163121         152300
508450           155641             148320              163139         152318
508500           155659             148337              163156         152335
508550           155676             148355              163174         152353
508600           155694             148372              163191         152370
508650           155711             148390              163209         152388
508700           155729             148407              163226         152405
508750           155746             148425              163244         152423
508800           155764             148442              163261         152440
508850           155781             148460              163279         152458
508900           155799             148477              163296         152475
508950           155816             148495              163314         152493
509000           155834             148512              163331         152510
509050           155851             148530              163349         152528
509100           155869             148547              163366         152545
509150           155886             148565              163384         152563
509200           155904             148582              163401         152580
509250           155921             148600              163419         152598
509300           155939             148617              163436         152615
509350           155956             148635              163454         152633
509400           155974             148652              163471         152650
509450           155991             148670              163489         152668
509500           156009             148687              163506         152685
509550           156026             148705              163524         152703
509600           156044             148722              163541         152720
509650           156061             148740              163559         152738
509700           156079             148757              163576         152755
509750           156096             148775              163594         152773
509800           156114             148792              163611         152790
509850           156131             148810              163629         152808
509900           156149             148827              163646         152825
509950           156166             148845              163664         152843
*/
